using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;

namespace DataEntity
{
	public class T_Report_Attach : DBInteractionBase
	{
		#region Class Member Declarations
			private SqlInt32		_project_Report_ExchangeTypeID, _project_Report_FileID;
			private SqlString		_project_Report_FilePath, _project_Report_FileDesc, _project_Report_FileName;
			private SqlGuid			_project_Report_MainID, _project_Report_ID;
		#endregion


		public T_Report_Attach()
		{
			// Nothing for now.
		}





		public override bool Update()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_Attach_Update]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Report_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_Report_ID));
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Report_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_Report_MainID));
				cmdToExecute.Parameters.Add(new SqlParameter("@iProject_Report_ExchangeTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _project_Report_ExchangeTypeID));
				cmdToExecute.Parameters.Add(new SqlParameter("@iProject_Report_FileID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _project_Report_FileID));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Report_FileName", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_Report_FileName));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Report_FilePath", SqlDbType.NVarChar, 300, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_Report_FilePath));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Report_FileDesc", SqlDbType.NVarChar, 30, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_Report_FileDesc));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_Attach::Update::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}





		public override DataTable SelectOne()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_Attach_SelectOne]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Report_Attach");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Report_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_Report_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				if(toReturn.Rows.Count > 0)
				{
					_project_Report_ID = (Guid)toReturn.Rows[0]["Project_Report_ID"];
					_project_Report_MainID = (Guid)toReturn.Rows[0]["Project_Report_MainID"];
					_project_Report_ExchangeTypeID = (Int32)toReturn.Rows[0]["Project_Report_ExchangeTypeID"];
					_project_Report_FileID = (Int32)toReturn.Rows[0]["Project_Report_FileID"];
					_project_Report_FileName = (string)toReturn.Rows[0]["Project_Report_FileName"];
					_project_Report_FilePath = (string)toReturn.Rows[0]["Project_Report_FilePath"];
					_project_Report_FileDesc = (string)toReturn.Rows[0]["Project_Report_FileDesc"];
				}
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_Attach::SelectOne::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		public override DataTable SelectAll()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_Attach_SelectAll]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Report_Attach");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_Attach::SelectAll::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		#region Class Property Declarations
		public SqlGuid Project_Report_ID
		{
			get
			{
				return _project_Report_ID;
			}
			set
			{
				_project_Report_ID = value;
			}
		}


		public SqlGuid Project_Report_MainID
		{
			get
			{
				return _project_Report_MainID;
			}
			set
			{
				SqlGuid project_Report_MainIDTmp = (SqlGuid)value;
				if(project_Report_MainIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_Report_MainID", "Project_Report_MainID can't be NULL");
				}
				_project_Report_MainID = value;
			}
		}


		public SqlInt32 Project_Report_ExchangeTypeID
		{
			get
			{
				return _project_Report_ExchangeTypeID;
			}
			set
			{
				SqlInt32 project_Report_ExchangeTypeIDTmp = (SqlInt32)value;
				if(project_Report_ExchangeTypeIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_Report_ExchangeTypeID", "Project_Report_ExchangeTypeID can't be NULL");
				}
				_project_Report_ExchangeTypeID = value;
			}
		}


		public SqlInt32 Project_Report_FileID
		{
			get
			{
				return _project_Report_FileID;
			}
			set
			{
				SqlInt32 project_Report_FileIDTmp = (SqlInt32)value;
				if(project_Report_FileIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_Report_FileID", "Project_Report_FileID can't be NULL");
				}
				_project_Report_FileID = value;
			}
		}


		public SqlString Project_Report_FileName
		{
			get
			{
				return _project_Report_FileName;
			}
			set
			{
				SqlString project_Report_FileNameTmp = (SqlString)value;
				if(project_Report_FileNameTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_Report_FileName", "Project_Report_FileName can't be NULL");
				}
				_project_Report_FileName = value;
			}
		}


		public SqlString Project_Report_FilePath
		{
			get
			{
				return _project_Report_FilePath;
			}
			set
			{
				SqlString project_Report_FilePathTmp = (SqlString)value;
				if(project_Report_FilePathTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_Report_FilePath", "Project_Report_FilePath can't be NULL");
				}
				_project_Report_FilePath = value;
			}
		}


		public SqlString Project_Report_FileDesc
		{
			get
			{
				return _project_Report_FileDesc;
			}
			set
			{
				SqlString project_Report_FileDescTmp = (SqlString)value;
				if(project_Report_FileDescTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_Report_FileDesc", "Project_Report_FileDesc can't be NULL");
				}
				_project_Report_FileDesc = value;
			}
		}
		#endregion
	}
}
